﻿using SSCAI.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SSCAI.Filter
{
    public class FilterHelper
    {
        public static int kill012Count = 1;
        public static int kill0123Count = 1;
        public static int kill01234Count = 1;

        // 两个号码相减得0 下期胆码设置0-5  1设置1-6    2设置2-7  3的话设置3-8  4设置4-9   5设置0-5   6设置1-6  7设置2-7   8设置3-8     9设置4-9
        private static readonly List<string> danMa = new List<string>() { "012345", "123456", "234567", "345678", "456789", "012345", "123456", "234567", "345678", "456789" };

        public static int latestDanMaIndex = 0;

        public static string maxWeiCoolCodes = string.Empty;

        public static string maxWeiHotCodes = string.Empty;

        public static List<LotteryModel> dataSource = new List<LotteryModel>();

        public static List<LotteryModel> LatestTwoHundred { get; set; }

        public static List<int> LatestOneHundredProduct { get; set; }//暂定获取最近100期 乘积，实际值在GetFiters()中定义

        public static List<string> LatestOneHundredPositionDifference { get; set; }//暂定获取最近100期 位差，实际值在GetFiters()中定义

        /// <summary>
        ///  最后200期号码list
        /// </summary>
        public static List<string> Last200Lotterys { get; set; }

        public static int LastNLotterys { get; set; }

        /// <summary>
        /// 最近n期的01234特征码list
        /// </summary>
        public static List<string> Last01234Number { get; set; }
        /// <summary>
        /// 最近n期的0123特征码list
        /// </summary>
        public static List<string> Last0123Number { get; set; }

        /// <summary>
        /// 最近n期的012特征码list
        /// </summary>
        public static List<string> Last012Number { get; set; }

        /// <summary>
        /// 最近两期号码
        /// </summary>
        public static List<LotteryModel> LastTwoLotterys { get; set; }

        /// <summary>
        /// 最近四期号码
        /// </summary>
        public static List<LotteryModel> LastFourLotterys { get; set; }

        /// <summary>
        /// 随机数组
        /// </summary>
        public static List<string> RandomList { get; set; }

        /// <summary>
        /// 上期号码
        /// </summary>
        public static LotteryModel LastLottery { get; set; }

        /// <summary>
        /// 同时杀错的次数 
        /// </summary>
        public static int KillCounter = 0;

        public static int selectedCounter = 0;

        public static int SelectedSolution = 0;//0:方案一，1：方案二，2：方案三

        /// <summary>
        /// 啥都不干
        /// </summary>
        public static void FilterNothing(LotteryModel data)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        public static void KillRandom(LotteryModel data)
        {
            Random r = new Random();
            if (data.FourDNumber == r.Next(0, 9999).ToString("0000"))
            {
                data.IsValid = false;
            }
        }

        /// <summary>
        /// 杀相等数据，例如：1111，2222 ....
        /// </summary>
        /// <param name="data"></param>
        public static void KillLoepardData(LotteryModel data)
        {
            #region //判断是否有重复值
            List<int> flagIsDistinectListOfData = new List<int>();
            flagIsDistinectListOfData.Add(data.QianWei);
            flagIsDistinectListOfData.Add(data.BaiWei);
            flagIsDistinectListOfData.Add(data.ShiWei);
            flagIsDistinectListOfData.Add(data.GeWei);

            List<int> afterDisOfData = flagIsDistinectListOfData.Distinct().ToList<int>();
            int afterDisOfLatestNumberCount = afterDisOfData.Count();//4：没有重复值，3：有2个值相同,2:有三个值相同
            #endregion


            if (FilterHelper.SelectedSolution == 1)//方案二
            {
                if (data.GeWei == data.ShiWei && data.ShiWei == data.BaiWei && data.BaiWei == data.QianWei)
                {
                    KillCounter++;
                }
            }
            if (FilterHelper.SelectedSolution == 0)//方案一
            {
                if ((data.GeWei == data.ShiWei && data.ShiWei == data.BaiWei) || (data.ShiWei == data.BaiWei && data.BaiWei == data.QianWei))
                {
                    KillCounter++;
                }
            }
            if (FilterHelper.SelectedSolution == 2)
            {
                if (afterDisOfLatestNumberCount == 2)
                {
                    KillCounter++;
                }
            }

        }

        /// <summary>
        /// 杀上一期的和值
        /// </summary>
        /// <param name="data"></param>
        public static void KillSumData(LotteryModel data)
        {
            ////int count = Math.Abs(data.FourDSum - FilterHelper.LastLottery.FourDSum);
            ////if (count <= 3)

            ////if (data.FourDSum == FilterHelper.LastLottery.FourDSum)
            ////{
            ////    KillCounter++;
            ////}

            //if (data.FourDSum % 10 == FilterHelper.LastLottery.FourDSum % 10)
            //{
            //    KillCounter++;
            //}

            ////if (data.FourDSum / 10 == FilterHelper.LastLottery.FourDSum / 10)
            ////{
            ////    KillCounter++;
            ////}


            if (FilterHelper.SelectedSolution == 1)
            {
                if (data.FourDSum == FilterHelper.LastTwoLotterys.First().FourDSum && data.FourDSum == FilterHelper.LastTwoLotterys.Last().FourDSum)
                {
                    KillCounter++;
                }



                int dqian = data.QianWei;
                int dbbai = data.BaiWei;
                int dshi = data.ShiWei;
                int dge = data.GeWei;

                int q = FilterHelper.LastLottery.QianWei;
                int b = FilterHelper.LastLottery.QianWei;
                int s = FilterHelper.LastLottery.QianWei;
                int g = FilterHelper.LastLottery.QianWei;
                //千百十 ， 千百个，百十个，钱是个，
                if ((dqian == q && dbbai == b && dshi == s) || (dqian == q && dbbai == b && dge == g) || (dbbai == b && dshi == s && dge == g) || (dqian == q && dshi == s && dge == g))
                {
                    KillCounter++;
                }
            }
            if (FilterHelper.SelectedSolution == 0 || FilterHelper.SelectedSolution == 2)
            {
                if (data.FourDSum == FilterHelper.LastLottery.FourDSum)
                {
                    KillCounter++;
                }
            }

           
        }

        /// <summary>
        /// 杀跨度和
        /// </summary>
        /// <param name="data"></param>
        public static void KillKuaDuHe(LotteryModel data)
        {
            //最近的一期
            int geWei1 = FilterHelper.LastTwoLotterys.First().GeWei;
            int shiWei1 = FilterHelper.LastTwoLotterys.First().ShiWei;
            int baiWei1 = FilterHelper.LastTwoLotterys.First().BaiWei;
            int qianWei1 = FilterHelper.LastTwoLotterys.First().QianWei;

            //最近的倒数第二期
            int geWei2 = FilterHelper.LastTwoLotterys.Last().GeWei;
            int shiWei2 = FilterHelper.LastTwoLotterys.Last().ShiWei;
            int baiWei2 = FilterHelper.LastTwoLotterys.Last().BaiWei;
            int qianWei2 = FilterHelper.LastTwoLotterys.Last().QianWei;

            //上期开奖号码和上上期跨度
            int absGeWei = Math.Abs(geWei1 - geWei2);
            int absShiWei = Math.Abs(shiWei1 - shiWei2);
            int absBaiWei = Math.Abs(baiWei1 - baiWei2);
            int absQianWei = Math.Abs(qianWei1 - qianWei2);
            int sum1 = absGeWei + absShiWei + absBaiWei + absQianWei;

            //下期开奖号码和这期的跨度
            int absGeWei2 = Math.Abs(data.GeWei - geWei1);
            int absShiWei2 = Math.Abs(data.ShiWei - shiWei1);
            int absBaiWei2 = Math.Abs(data.BaiWei - baiWei1);
            int absQianWei2 = Math.Abs(data.QianWei - qianWei1);
            int sum2 = absGeWei2 + absShiWei2 + absBaiWei2 + absQianWei2;




            //int subtration = Math.Abs(sum1 - sum2);
            //if (subtration <= 3)
            //{
            //    KillCounter++;
            //}

            if (sum1 == sum2)
            {
                KillCounter++;
            }
        }

        /// <summary>
        /// 杀相同跨度
        /// </summary>
        public static void KillXiangTongKuaDu(LotteryModel data)
        {
            int absGeWei = Math.Abs(data.GeWei - FilterHelper.LastLottery.GeWei);
            int absShiWei = Math.Abs(data.ShiWei - FilterHelper.LastLottery.ShiWei);
            int absBaiWei = Math.Abs(data.BaiWei - FilterHelper.LastLottery.BaiWei);
            int absQianWei = Math.Abs(data.QianWei - FilterHelper.LastLottery.QianWei);

            List<int> list = new List<int>();
            list.Add(absGeWei);
            list.Add(absShiWei);
            list.Add(absBaiWei);
            list.Add(absQianWei);

            int count = list.Distinct().ToList<int>().Count;////4：没有重复值，3：有2个值相同,2:有三个值相同,1:四个值相同

            if (FilterHelper.SelectedSolution == 1)//方案二
            {
                if (count == 1) KillCounter++;
            }
            else//方案一 or 方案三
            {
                if (count == 2) KillCounter++;
            }
        }

        /// <summary>
        /// 杀顺子跨度
        /// </summary>
        /// <param name="data"></param>
        public static void KillShunZiKuaDu(LotteryModel data)
        {
            var latestOne = FilterHelper.LastLottery;

            int absGeWei = Math.Abs(data.GeWei - latestOne.GeWei);
            int absShiWei = Math.Abs(data.ShiWei - latestOne.ShiWei);
            int absBaiWei = Math.Abs(data.BaiWei - latestOne.BaiWei);
            int absQianWei = Math.Abs(data.QianWei - latestOne.QianWei);

            int a1 = absGeWei - absShiWei;
            int a2 = absShiWei - absBaiWei;
            int a3 = absBaiWei - absQianWei;



            List<int> list = new List<int>();
            list.Add(absQianWei);
            list.Add(absBaiWei);
            list.Add(absShiWei);
            list.Add(absGeWei);

            list.Sort();

            int a = list[0] - list[1];
            int b = list[1] - list[2];
            int c = list[2] - list[3];

            if (FilterHelper.SelectedSolution == 1)//方案二
            {
                //if ((a == 1 && b == 1 && c == 1) || (a == -1 && b == -1 && c == -1))//1234
                //{
                //    KillCounter++;
                //}

                if ((a1 == 1 && a2 == 1 && a3 == 1) || (a1 == -1 && a2 == -1 && a3 == -1))
                {
                    KillCounter++;
                }
            }
            if (FilterHelper.SelectedSolution == 0)
            {


                if ((a == 1 && b == 1 && c == 1) || (a == -1 && b == -1 && c == -1))//123,234
                {
                    KillCounter++;
                }
            }
            if (FilterHelper.SelectedSolution == 2)
            {
                if ((a == 1 && b == 1) || (b == 1 && c == 1) || (a == -1 && b == -1) || (b == -1 && c == -1))//123,234
                {
                    KillCounter++;
                }
            }

        }

        /// <summary>
        /// 杀掉最近200期
        /// </summary>
        /// <param name="data"></param>
        public static void KillQian200(LotteryModel data)
        {
            int count = 0;

            if (FilterHelper.Last200Lotterys.Contains(data.FourDNumber))
            {
                count++;
            }

            if (count > 0) KillCounter++;
        }

        /// <summary>
        /// 杀顺子1234，2345...
        /// </summary>
        /// <param name="data"></param>
        public static void KillShunZi(LotteryModel data)
        {
            int a = data.ShiWei - data.GeWei;
            int b = data.BaiWei - data.ShiWei;
            int c = data.QianWei - data.BaiWei;

            if (FilterHelper.SelectedSolution == 1)//方案二
            {
                if ((a == 1 && b == 1 && c == 1) || (a == -1 && b == -1 && c == -1))
                {
                    KillCounter++;
                }
            }
            else
            {
                if ((a == 1 && b == 1) || (b == 1 && c == 1) || (a == -1 && b == -1) || (b == -1 && c == -1))
                {
                    KillCounter++;
                }
            }

        }

        /// <summary>
        /// 按位过滤最冷号
        /// </summary>
        /// <param name="data"></param>
        public static void KillEveryWeiZuiLengHao(LotteryModel data)
        {
            int counter = 0;
            if (FilterHelper.maxWeiCoolCodes.Substring(0, 1) == data.QianWei.ToString()) { counter++; }
            if (FilterHelper.maxWeiCoolCodes.Substring(1, 1) == data.BaiWei.ToString()) { counter++; }
            if (FilterHelper.maxWeiCoolCodes.Substring(2, 1) == data.ShiWei.ToString()) { counter++; }
            if (FilterHelper.maxWeiCoolCodes.Substring(3, 1) == data.GeWei.ToString()) { counter++; }

            if (FilterHelper.SelectedSolution == 0)
            {
                //if (counter >= 3)
                //{
                //    KillCounter++;
                //}

                if (counter < 1)//6561
                {
                    KillCounter++;
                }
            }
            if (FilterHelper.SelectedSolution == 1)
            {
                if (counter > 2)
                {
                    KillCounter++;
                }
            }
            if (FilterHelper.SelectedSolution == 2)
            {
                if (counter < 1)//6561
                {
                    KillCounter++;
                }
            }


        }

        /// <summary>
        /// 按位过滤最热号
        /// </summary>
        /// <param name="data"></param>
        public static void KillEveryWeiZuiReHao(LotteryModel data)
        {
            int counter = 0;
            if (FilterHelper.maxWeiHotCodes.Substring(0, 1) == data.QianWei.ToString()) { counter++; }
            if (FilterHelper.maxWeiHotCodes.Substring(1, 1) == data.BaiWei.ToString()) { counter++; }
            if (FilterHelper.maxWeiHotCodes.Substring(2, 1) == data.ShiWei.ToString()) { counter++; }
            if (FilterHelper.maxWeiHotCodes.Substring(3, 1) == data.GeWei.ToString()) { counter++; }

            if (FilterHelper.SelectedSolution == 0)
            {
                //if (counter > 2)
                //{
                //    KillCounter++;
                //}

                if (counter < 2)//6561
                {
                    KillCounter++;
                }
            }
            if (FilterHelper.SelectedSolution == 1)
            {
                if (counter > 2)
                {
                    KillCounter++;
                }
                //if (counter < 1)
                //{
                //    KillCounter++;
                //}
            }
            if (FilterHelper.SelectedSolution == 2)
            {
                if (counter < 1)//6561
                {
                    KillCounter++;
                }
            }

        }

        /// <summary>
        /// 取得每位的最热码
        /// </summary>
        /// <returns></returns>
        public static string GetWeiHotCodes()
        {
            int[] geWei = new int[10] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
            int[] shiWei = new int[10] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
            int[] baiWei = new int[10] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
            int[] qianWei = new int[10] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };

            int count = FilterHelper.dataSource.Count();
            for (int i = 0; i < 50 && i < count; i++)
            {

                geWei[dataSource[i].GeWei]++;
                shiWei[dataSource[i].ShiWei]++;
                baiWei[dataSource[i].BaiWei]++;
                qianWei[dataSource[i].QianWei]++;

            }

            int gMax = 0;
            int sMax = 0;
            int bMax = 0;
            int qMax = 0;

            for (int i = 0; i < 10; i++)
            {
                if (geWei[i] == geWei.Max())
                {
                    gMax = i;
                }

                if (shiWei[i] == shiWei.Max())
                {
                    sMax = i;
                }

                if (baiWei[i] == baiWei.Max())
                {
                    bMax = i;
                }

                if (qianWei[i] == qianWei.Max())
                {
                    qMax = i;
                }
            }

            return string.Concat(qMax, bMax, sMax, gMax);
        }

        /// <summary>
        /// 取得每位的最冷码
        /// </summary>
        /// <returns></returns>
        public static string GetWeiCoolCodes()
        {
            int[] geWei = new int[10] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
            int[] shiWei = new int[10] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
            int[] baiWei = new int[10] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
            int[] qianWei = new int[10] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };

            int count = FilterHelper.dataSource.Count();
            for (int i = 0; i < count; i++)
            {
                if (geWei[dataSource[i].GeWei] == -1)
                {
                    geWei[dataSource[i].GeWei] = i;
                }

                if (shiWei[dataSource[i].ShiWei] == -1)
                {
                    shiWei[dataSource[i].ShiWei] = i;
                }

                if (baiWei[dataSource[i].BaiWei] == -1)
                {
                    baiWei[dataSource[i].BaiWei] = i;
                }

                if (qianWei[dataSource[i].QianWei] == -1)
                {
                    qianWei[dataSource[i].QianWei] = i;
                }
            }

            int gMax = 0;
            int sMax = 0;
            int bMax = 0;
            int qMax = 0;

            for (int i = 0; i < 10; i++)
            {
                if (geWei[i] == geWei.Max())
                {
                    gMax = i;
                }

                if (shiWei[i] == shiWei.Max())
                {
                    sMax = i;
                }

                if (baiWei[i] == baiWei.Max())
                {
                    bMax = i;
                }

                if (qianWei[i] == qianWei.Max())
                {
                    qMax = i;
                }
            }

            return string.Concat(qMax, bMax, sMax, gMax);
        }

        /// <summary>
        /// 杀上期012路 20内的
        /// </summary>
        /// <param name="data"></param>
        public static void Kill012(LotteryModel data)
        {
            if (FilterHelper.Last012Number.Contains(data.Number012))
            {
                KillCounter++;
            }
        }

        /// <summary>
        /// 杀上期0123路 40n内的
        /// </summary>
        /// <param name="data"></param>
        public static void Kill0123(LotteryModel data)
        {
            if (FilterHelper.Last0123Number.Contains(data.Number0123))
            {
                KillCounter++;
            }
        }

        /// <summary>
        /// 杀上期01234路
        /// </summary>
        /// <param name="data"></param>
        public static void Kill01234(LotteryModel data)
        {
            if (FilterHelper.Last01234Number.Contains(data.Number01234))
            {
                KillCounter++;
            }
        }

        /// <summary>
        /// Kill Two Two group
        /// </summary>
        /// <param name="data"></param>
        public static void KillTwoTwoGroup(LotteryModel data)
        {

        }

        /// <summary>
        /// 两个号码相减得0 下期胆码设置0-5  1设置1-6    2设置2-7  3的话设置3-8  4设置4-9   5设置0-5   6设置1-6  7设置1-7   8设置3-8     9设置4-9
        /// </summary>
        /// <param name="data"></param>
        public static void DanMa(LotteryModel data)
        {
            string strDan = string.Concat("!-!", danMa[latestDanMaIndex]);

            strDan = strDan.Replace(data.GeWei.ToString(), "!-!")
                 .Replace(data.ShiWei.ToString(), "!-!")
                 .Replace(data.BaiWei.ToString(), "!-!")
                 .Replace(data.QianWei.ToString(), "!-!");
            int counter = strDan.Split('-').Length;

            if (FilterHelper.SelectedSolution == 1)//方案二
            {
                data.IsValid = counter < 7 && counter > 2;
            }
            else//方案一 or 方案三
            {
                //data.IsValid = counter < 6 && counter > 2;
                data.IsValid = counter < 7 && counter > 2;
            }

            if (data.IsValid == false)
            {
                KillCounter++;
            }

        }

        /// <summary>
        /// 杀和尾
        /// </summary>
        /// <param name="data"></param>
        public static void KillSumTail(LotteryModel data)
        {
            // if (!data.IsValid) return;
            //string[] strShunZi = new string[] { "789", "890", "910", "012", "123", "234", "345", "456", "567", "678" };
            //string[] strShunZi2 = new string[] { "987", "098", "109", "210", "321", "432", "543", "654", "756", "876" };
            //var shunZiTail = string.Concat(FilterHelper.LastFourLotterys[0].FourDSumTail, FilterHelper.LastFourLotterys[1].FourDSumTail, FilterHelper.LastFourLotterys[2].FourDSumTail);
            //int? killTail = null;

            //for (int i = 0; i < 10; i++)
            //{
            //    if (shunZiTail == strShunZi[i] || shunZiTail == strShunZi2[i])
            //    {
            //        killTail = i;
            //        break;
            //    }

            //}

            //if (null != killTail)
            //{
            //    if (data.FourDSumTail == killTail)
            //    {
            //        data.IsValid = false;
            //    }
            //}

            var aTail = FilterHelper.LastFourLotterys[0].FourDSumTail;
            var bTail = FilterHelper.LastFourLotterys[1].FourDSumTail;
            var cTail = FilterHelper.LastFourLotterys[2].FourDSumTail;
            var dTail = FilterHelper.LastFourLotterys[3].FourDSumTail;

            var a_b = aTail - bTail;
            var b_c = bTail - cTail;
            var c_d = cTail - dTail;

            if (a_b == b_c && b_c == c_d && (c_d == 1 || c_d == -1))
            {
                if (data.FourDSumTail == aTail + 1)
                {
                    data.IsValid = false;
                }
            }


            if (a_b == 0 && b_c == 0)
            {
                if (data.FourDSumTail == FilterHelper.LastFourLotterys[0].FourDSumTail)
                {
                    data.IsValid = false;
                }
            }

            //if (FilterHelper.LastFourLotterys[0].BaiWei == FilterHelper.LastFourLotterys[1].BaiWei && FilterHelper.LastFourLotterys[1].BaiWei == FilterHelper.LastFourLotterys[2].BaiWei)
            //{
            //    if (data.BaiWei == FilterHelper.LastFourLotterys[0].BaiWei)
            //    {
            //        data.IsValid = false;
            //    }

            //}

            //if (FilterHelper.LastFourLotterys[0].QianWei == FilterHelper.LastFourLotterys[1].QianWei && FilterHelper.LastFourLotterys[1].QianWei == FilterHelper.LastFourLotterys[2].QianWei)
            //{
            //    if (data.QianWei == FilterHelper.LastFourLotterys[0].QianWei)
            //    {
            //        data.IsValid = false;
            //    }

            //}

            //if (FilterHelper.LastFourLotterys[0].ShiWei == FilterHelper.LastFourLotterys[1].ShiWei && FilterHelper.LastFourLotterys[1].ShiWei == FilterHelper.LastFourLotterys[2].ShiWei)
            //{
            //    if (data.ShiWei == FilterHelper.LastFourLotterys[0].ShiWei)
            //    {
            //        data.IsValid = false;
            //    }

            //}

            //if (FilterHelper.LastFourLotterys[0].GeWei == FilterHelper.LastFourLotterys[1].GeWei && FilterHelper.LastFourLotterys[1].GeWei == FilterHelper.LastFourLotterys[2].GeWei)
            //{
            //    if (data.GeWei == FilterHelper.LastFourLotterys[0].GeWei)
            //    {
            //        data.IsValid = false;
            //    }

            //}

            //if (FilterHelper.LastLottery.FourDSum < 10)
            //{
            //    if (data.FourDSum < 10) data.IsValid = false;
            //}

            //if (FilterHelper.LastLottery.FourDSum > 29)
            //{
            //    if (data.FourDSum > 29)
            //        data.IsValid = false;
            //}


            if (FilterHelper.LastTwoLotterys[0].Number01 == FilterHelper.LastTwoLotterys[1].Number01)
            {

                var number = FilterHelper.LastTwoLotterys[0].Number01;
                number = number.Replace("1", "2");
                number = number.Replace("0", "1");
                number = number.Replace("2", "1");

                if (data.Number01 == FilterHelper.LastTwoLotterys[0].Number01 || data.Number01 == number)
                {
                    data.IsValid = false;
                }
            }

            if (FilterHelper.LastTwoLotterys[0].Number01 == "1111" || FilterHelper.LastTwoLotterys[0].Number01 == "0000")
            {
                if (data.Number01 == "1111" || data.Number01 == "0000")
                {
                    data.IsValid = false;
                }

                if (data.FourDSumTail == FilterHelper.LastTwoLotterys[0].FourDSumTail)
                {
                    data.IsValid = false;
                }
            }

            if (FilterHelper.LastTwoLotterys[0].Number01 == "0001" || FilterHelper.LastTwoLotterys[0].Number01 == "1000")
            {

                if (data.FourDSumTail == 1)
                {
                    data.IsValid = false;
                }
            }

        }



        /// <summary>
        /// 过滤上期大到小
        /// </summary>
        /// <param name="data"></param>
        public static void KillBigToSmall(LotteryModel data)
        {
            int geOfData = data.GeWei;
            int shiOfData = data.ShiWei;
            int baiOfData = data.BaiWei;
            int qianOfData = data.QianWei;

            int[] datas = { qianOfData, baiOfData, shiOfData, geOfData };

            #region Kill 从大到小

            string bigToSmallNumber = FilterHelper.LastLottery.BigToSmall;
            int qianOfBigToSmall = Convert.ToInt16(bigToSmallNumber.Substring(0, 1));
            int baiOfBigToSmall = Convert.ToInt16(bigToSmallNumber.Substring(1, 1));
            int shiOfBigToSmall = Convert.ToInt16(bigToSmallNumber.Substring(2, 1));
            int geOfBigToSmall = Convert.ToInt16(bigToSmallNumber.Substring(3, 1));

            int[] lastestDatas = { qianOfBigToSmall, baiOfBigToSmall, shiOfBigToSmall, geOfBigToSmall };

            int counter = 0;
            for (int i = 0; i < lastestDatas.Length; i++)
            {
                if (lastestDatas[i] == datas[i])
                {
                    counter++;
                }
            }

            if (FilterHelper.SelectedSolution == 1)//The second solution
            {
                if (counter >= 3)
                {
                    KillCounter++;
                }
            }
            if (FilterHelper.SelectedSolution == 0)
            {
                if (counter >= 3)
                {
                    KillCounter++;
                }
            }
            if (FilterHelper.SelectedSolution == 2)//方案三
            {
                if (counter >= 2)
                {
                    KillCounter++;
                }
            }

            #endregion
        }

        /// <summary>
        /// 过滤上期小到大
        /// </summary>
        /// <param name="data"></param>
        public static void KillSmallToBig(LotteryModel data)
        {
            int geOfData = data.GeWei;
            int shiOfData = data.ShiWei;
            int baiOfData = data.BaiWei;
            int qianOfData = data.QianWei;

            int[] datas = { qianOfData, baiOfData, shiOfData, geOfData };

            #region Kill 从小到大

            string smallToBig = FilterHelper.LastLottery.SmallToBig;
            int qianOfSmallToBig = Convert.ToInt16(smallToBig.Substring(0, 1));
            int baiOfSmallToBig = Convert.ToInt16(smallToBig.Substring(1, 1));
            int shiOfSmallToBig = Convert.ToInt16(smallToBig.Substring(2, 1));
            int geOfSmallToBig = Convert.ToInt16(smallToBig.Substring(3, 1));

            int[] lastestDatas = { qianOfSmallToBig, baiOfSmallToBig, shiOfSmallToBig, geOfSmallToBig };

            int counter = 0;
            for (int i = 0; i < lastestDatas.Length; i++)
            {
                if (lastestDatas[i] == datas[i])
                {
                    counter++;
                }
            }

            if (FilterHelper.SelectedSolution == 1)//方案二 （放宽）
            {
                if (counter >= 3)
                {
                    KillCounter++;
                }
            }
            if (FilterHelper.SelectedSolution == 0)
            {
                if (counter >= 3)
                {
                    KillCounter++;
                }
            }
            if (FilterHelper.SelectedSolution == 2)
            {
                if (counter >= 2)
                {
                    KillCounter++;
                }
            }


            #endregion

        }

        /// <summary>
        /// 过滤乘积
        /// </summary>
        /// <param name="data"></param>
        public static void KillProduct(LotteryModel data)
        {
            if (LatestOneHundredProduct.Contains(data.Product))
            {
                KillCounter++;
            }
        }

        /// <summary>
        /// 过滤位差
        /// </summary>
        /// <param name="data"></param>
        public static void KillPositionDifference(LotteryModel data)
        {
            if (LatestOneHundredPositionDifference.Contains(data.FourDDeviation))
            {
                KillCounter++;
            }
        }

        /// <summary>
        /// 过滤上期号码
        /// </summary>
        /// <param name="data"></param>
        public static void KillShangQiKaiJiangHaoMa(LotteryModel data)
        {
            //判断是否有重复值
            List<int> flagIsDistinectListOfLatestNumber = new List<int>();
            flagIsDistinectListOfLatestNumber.Add(FilterHelper.LastLottery.QianWei);
            flagIsDistinectListOfLatestNumber.Add(FilterHelper.LastLottery.BaiWei);
            flagIsDistinectListOfLatestNumber.Add(FilterHelper.LastLottery.ShiWei);
            flagIsDistinectListOfLatestNumber.Add(FilterHelper.LastLottery.GeWei);

            List<int> afterDisOfLatestNumberList = flagIsDistinectListOfLatestNumber.Distinct().ToList<int>();
            int afterDisOfLatestNumberCount = afterDisOfLatestNumberList.Count();//4：没有重复值，3：有2个值相同

            ////计算未包含的数据
            //List<int> unincludeDatas = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            //if (afterDisOfLatestNumberCount == 4)
            //{
            //    unincludeDatas.Remove(afterDisOfLatestNumberList[0]);
            //    unincludeDatas.Remove(afterDisOfLatestNumberList[1]);
            //    unincludeDatas.Remove(afterDisOfLatestNumberList[2]);
            //    unincludeDatas.Remove(afterDisOfLatestNumberList[3]);
            //}
            //else if (afterDisOfLatestNumberCount == 3)
            //{
            //    unincludeDatas.Remove(afterDisOfLatestNumberList[0]);
            //    unincludeDatas.Remove(afterDisOfLatestNumberList[1]);
            //    unincludeDatas.Remove(afterDisOfLatestNumberList[2]);
            //}
            //else if (afterDisOfLatestNumberCount == 2)
            //{
            //    unincludeDatas.Remove(afterDisOfLatestNumberList[0]);
            //    unincludeDatas.Remove(afterDisOfLatestNumberList[1]);
            //}

            //Ready
            List<string> list = new List<string>();//Generated datas
            List<string> distinctList = null;
            int distinctCount = 0;

            #region 有2对相同的值
            //if (afterDisOfLatestNumberCount == 2)
            //{
            //    for (int i = 0; i < 2; i++)
            //    {
            //        for (int j = 0; j < unincludeDatas.Count; j++)
            //        {
            //            if (i == 0)
            //            {
            //                list.Add(afterDisOfLatestNumberList[i].ToString() + afterDisOfLatestNumberList[i + 1] + afterDisOfLatestNumberList[i] + unincludeDatas[j]);
            //                list.Add(afterDisOfLatestNumberList[i].ToString() + afterDisOfLatestNumberList[i + 1] + unincludeDatas[j] + afterDisOfLatestNumberList[i]);
            //                list.Add(afterDisOfLatestNumberList[i].ToString() + unincludeDatas[j] + afterDisOfLatestNumberList[i + 1] + afterDisOfLatestNumberList[i]);
            //                list.Add(unincludeDatas[j] + afterDisOfLatestNumberList[i].ToString() + afterDisOfLatestNumberList[i + 1] + afterDisOfLatestNumberList[i]);
            //            }
            //            else
            //            {
            //                list.Add(afterDisOfLatestNumberList[i].ToString() + afterDisOfLatestNumberList[i - 1] + afterDisOfLatestNumberList[i] + unincludeDatas[j]);
            //                list.Add(afterDisOfLatestNumberList[i].ToString() + afterDisOfLatestNumberList[i - 1] + unincludeDatas[j] + afterDisOfLatestNumberList[i]);
            //                list.Add(afterDisOfLatestNumberList[i].ToString() + unincludeDatas[j] + afterDisOfLatestNumberList[i - 1] + afterDisOfLatestNumberList[i]);
            //                list.Add(unincludeDatas[j] + afterDisOfLatestNumberList[i].ToString() + afterDisOfLatestNumberList[i - 1] + afterDisOfLatestNumberList[i]);
            //            }

            //        }
            //    }

            //    distinctList = list.Distinct().ToList<string>();
            //    distinctCount = distinctList.Count;
            //}
            #endregion

            #region 上期号码有2个值相同
            //if (afterDisOfLatestNumberCount == 3)
            //{
            //    //3个任意数组合无重复
            //    string fourdNumber = afterDisOfLatestNumberList[0].ToString() + afterDisOfLatestNumberList[1] + afterDisOfLatestNumberList[2];
            //    char[] d = fourdNumber.ToCharArray();
            //    Pai(ref d, 0, d.Length, ref list);

            //    int[] array = { afterDisOfLatestNumberList[0], afterDisOfLatestNumberList[1], afterDisOfLatestNumberList[2] };

            //    for (int i = 0; i < array.Length; i++)
            //    {
            //        for (int k = 0; k < array.Length; k++)
            //        {
            //            for (int m = 0; m < array.Length; m++)
            //            {
            //                for (int j = 0; j < unincludeDatas.Count; j++)
            //                {
            //                    list.Add(array[i].ToString() + array[k] + array[m] + unincludeDatas[j]);
            //                    list.Add(array[i].ToString() + array[k] + unincludeDatas[j] + array[m]);
            //                    list.Add(array[i].ToString() + unincludeDatas[j] + array[k] + array[m]);
            //                    list.Add(unincludeDatas[j] + array[i].ToString() + array[k] + array[m]);
            //                }
            //            }
            //        }
            //    }

            //    distinctList = list.Distinct().ToList<string>();
            //    distinctCount = distinctList.Count;
            //}

            #endregion

            #region 上期号码没有重复值
            if (afterDisOfLatestNumberCount == 4)
            {
                //2359
                int qian = afterDisOfLatestNumberList[0];
                int bai = afterDisOfLatestNumberList[1];
                int shi = afterDisOfLatestNumberList[2];
                int ge = afterDisOfLatestNumberList[3];

                //4个任意组合无重复
                string fourdNumber = qian.ToString() + bai + shi + ge;
                char[] d = fourdNumber.ToCharArray();
                Pai(ref d, 0, d.Length, ref list);

                ////235 第一位235  第二位235  第三位235 第四位014678  这样就是3*3*3*6=162 235 235  014678  235 这又是162组

                //int[] firstGroup = { qian, bai, shi };

                //for (int i = 0; i < firstGroup.Length; i++)
                //{
                //    for (int k = 0; k < firstGroup.Length; k++)
                //    {
                //        for (int m = 0; m < firstGroup.Length; m++)
                //        {
                //            for (int j = 0; j < unincludeDatas.Count; j++)
                //            {
                //                list.Add(firstGroup[i].ToString() + firstGroup[k] + firstGroup[m] + unincludeDatas[j]);
                //                list.Add(firstGroup[i].ToString() + firstGroup[k] + unincludeDatas[j] + firstGroup[m]);
                //                list.Add(firstGroup[i].ToString() + unincludeDatas[j] + firstGroup[k] + firstGroup[m]);
                //                list.Add(unincludeDatas[j] + firstGroup[i].ToString() + firstGroup[k] + firstGroup[m]);
                //            }
                //        }
                //    }
                //}

                ////第二组 239
                //int[] secondGroup = { qian, bai, ge };

                //for (int i = 0; i < secondGroup.Length; i++)
                //{
                //    for (int k = 0; k < secondGroup.Length; k++)
                //    {
                //        for (int m = 0; m < secondGroup.Length; m++)
                //        {
                //            for (int j = 0; j < unincludeDatas.Count; j++)
                //            {
                //                list.Add(secondGroup[i].ToString() + secondGroup[k] + secondGroup[m] + unincludeDatas[j]);
                //                list.Add(secondGroup[i].ToString() + secondGroup[k] + unincludeDatas[j] + secondGroup[m]);
                //                list.Add(secondGroup[i].ToString() + unincludeDatas[j] + secondGroup[k] + secondGroup[m]);
                //                list.Add(unincludeDatas[j] + secondGroup[i].ToString() + secondGroup[k] + secondGroup[m]);
                //            }
                //        }
                //    }
                //}

                ////第三组 259
                //int[] thirdGroup = { qian, shi, ge };

                //for (int i = 0; i < thirdGroup.Length; i++)
                //{
                //    for (int k = 0; k < thirdGroup.Length; k++)
                //    {
                //        for (int m = 0; m < thirdGroup.Length; m++)
                //        {
                //            for (int j = 0; j < unincludeDatas.Count; j++)
                //            {
                //                list.Add(thirdGroup[i].ToString() + thirdGroup[k] + thirdGroup[m] + unincludeDatas[j]);
                //                list.Add(thirdGroup[i].ToString() + thirdGroup[k] + unincludeDatas[j] + thirdGroup[m]);
                //                list.Add(thirdGroup[i].ToString() + unincludeDatas[j] + thirdGroup[k] + thirdGroup[m]);
                //                list.Add(unincludeDatas[j] + thirdGroup[i].ToString() + thirdGroup[k] + thirdGroup[m]);
                //            }
                //        }
                //    }
                //}

                ////第三组 359
                //int[] forthGroup = { bai, shi, ge };

                //for (int i = 0; i < forthGroup.Length; i++)
                //{
                //    for (int k = 0; k < forthGroup.Length; k++)
                //    {
                //        for (int m = 0; m < forthGroup.Length; m++)
                //        {
                //            for (int j = 0; j < unincludeDatas.Count; j++)
                //            {
                //                list.Add(forthGroup[i].ToString() + forthGroup[k] + forthGroup[m] + unincludeDatas[j]);
                //                list.Add(forthGroup[i].ToString() + forthGroup[k] + unincludeDatas[j] + forthGroup[m]);
                //                list.Add(forthGroup[i].ToString() + unincludeDatas[j] + forthGroup[k] + forthGroup[m]);
                //                list.Add(unincludeDatas[j] + forthGroup[i].ToString() + forthGroup[k] + forthGroup[m]);
                //            }
                //        }
                //    }
                //}

                distinctList = list.Distinct().ToList<string>();
                distinctCount = distinctList.Count;
            }
            #endregion

            if (distinctCount > 0)
            {
                if (distinctList.Contains(data.FourDNumber))
                {
                    KillCounter++;
                }
            }
        }

        /// <summary>
        /// 过滤后四位胆码
        /// </summary>
        /// <param name="data"></param>
        public static void KillShangQiSiDanMa(LotteryModel data)
        {
            if (FilterData.FitlerDataListFD[FilterHelper.LastLottery.FourDNumber].Contains(data.FourDNumber))
            {
                KillCounter++;
            }
        }


        /// <summary>
        /// 过滤后三位胆码
        /// </summary>
        /// <param name="data"></param>
        public static void KillShangQiHouShanDanMa(LotteryModel data)
        {
            if (FilterData.FilerDataList[FilterHelper.LastLottery.FourDNumber.Substring(1, 3)].Contains(data.FourDNumber.Substring(1, 3)))
            {
                KillCounter++;
            }

        }

        /// <summary>
        /// 过滤三位胆码 3组
        /// </summary>
        /// <param name="data"></param>
        public static void KillShangQiHouShanDanMa3(LotteryModel data)
        {
            if (FilterData.FilerDataList[FilterHelper.LastLottery.FourDNumber.Substring(0, 3)].Contains(data.FourDNumber.Substring(0, 3)))
            {
                KillCounter++;
            }

            var key = FilterHelper.LastLottery.QianWei.ToString() + FilterHelper.LastLottery.FourDNumber.Substring(2, 2);
            string a = data.QianWei + data.ShiWei + data.GeWei.ToString();
            if (FilterData.FilerDataList[key].Contains(a))
            {
                KillCounter++;
            }

            key = FilterHelper.LastLottery.FourDNumber.Substring(0, 2) + FilterHelper.LastLottery.GeWei.ToString();
            string b = data.QianWei + data.BaiWei + data.GeWei.ToString();
            if (FilterData.FilerDataList[key].Contains(b))
            {
                KillCounter++;
            }

        }

        /// <summary>
        /// 过滤上期小中大号
        /// </summary>
        /// <param name="data"></param>
        public static void KillShangQiSmallMiddleBig(LotteryModel data)
        {
            //012小数  3456中号  789大号
            //以305为例，
            //下期不能出 中号 + 小号 + 中号组合

            //int[] arraySmall = { 0, 1, 2 };
            //int[] arrayMiddle = { 3, 4, 5, 6 };
            //int[] arrayBig = { 7, 8, 9 };

            int lastQian = FilterHelper.LastLottery.QianWei;
            int lastBai = FilterHelper.LastLottery.BaiWei;
            int lastShi = FilterHelper.LastLottery.ShiWei;
            int lastGe = FilterHelper.LastLottery.GeWei;

            int[] arrayQian = null;
            int[] arrayBai = null;
            int[] arrayShi = null;
            int[] arrayGe = null;

            //small
            if (lastQian >= 0 && lastQian <= 2) arrayQian = new int[] { 0, 1, 2 };
            if (lastBai >= 0 && lastBai <= 2) arrayBai = new int[] { 0, 1, 2 };
            if (lastShi >= 0 && lastShi <= 2) arrayShi = new int[] { 0, 1, 2 };
            if (lastGe >= 0 && lastGe <= 2) arrayGe = new int[] { 0, 1, 2 };
            //middle
            if (lastQian >= 3 && lastQian <= 6) arrayQian = new int[] { 3, 4, 5, 6 };
            if (lastBai >= 3 && lastBai <= 6) arrayBai = new int[] { 3, 4, 5, 6 };
            if (lastShi >= 3 && lastShi <= 6) arrayShi = new int[] { 3, 4, 5, 6 };
            if (lastGe >= 3 && lastGe <= 6) arrayGe = new int[] { 3, 4, 5, 6 };
            //big
            if (lastQian >= 7 && lastQian <= 9) arrayQian = new int[] { 7, 8, 9 };
            if (lastBai >= 7 && lastBai <= 9) arrayBai = new int[] { 7, 8, 9 };
            if (lastShi >= 7 && lastShi <= 9) arrayShi = new int[] { 7, 8, 9 };
            if (lastGe >= 7 && lastGe <= 9) arrayGe = new int[] { 7, 8, 9 };

            //string nextThreeNumbers = data.BaiWei.ToString() + data.ShiWei + data.GeWei;
            string nextFourNumbers = data.QianWei.ToString() + data.BaiWei.ToString() + data.ShiWei + data.GeWei;
            List<string> list = new List<string>();
            for (int n = 0; n < arrayQian.Length; n++)
            {
                for (int i = 0; i < arrayBai.Length; i++)
                {
                    for (int j = 0; j < arrayShi.Length; j++)
                    {
                        for (int k = 0; k < arrayGe.Length; k++)
                        {
                            ////3
                            //string lastThreeNumbers = arrayBai[i].ToString() + arrayShi[j] + arrayGe[k];
                            //list.Add(lastThreeNumbers);

                            //4
                            string lastFourNumbers = arrayQian[n] + arrayBai[i].ToString() + arrayShi[j] + arrayGe[k];
                            list.Add(lastFourNumbers);

                        }
                    }
                }
            }

            int count = list.Count;

            if (list.Contains(nextFourNumbers))
            {
                KillCounter++;
            }

            //if (list.Contains(nextThreeNumbers))
            //{
            //    KillCounter++;
            //}
        }

        /// <summary>
        /// 后两位相减
        /// </summary>
        /// <param name="data"></param>
        public static void KillLastTwoNumsSubtraction(LotteryModel data)
        {
            //int substraction = Math.Abs(data.LastTwoNumbsSubtraction - FilterHelper.LastLottery.LastTwoNumbsSubtraction);
            //if (substraction >= 0 && substraction <= 3)
            if (data.LastTwoNumbsSubtraction == FilterHelper.LastLottery.LastTwoNumbsSubtraction)
            {
                KillCounter++;
            }
        }

        /// <summary>
        /// 后两位相加
        /// </summary>
        /// <param name="data"></param>
        public static void KillLastTwoNumsSum(LotteryModel data)
        {
            //int ds = data.LastTwoNumsSum % 10;
            //int ls = FilterHelper.LastLottery.LastTwoNumsSum % 10;
            //if (ds == ls)

            //if (data.LastTwoNumsSum / 10 == FilterHelper.LastLottery.LastTwoNumsSum / 10)
            //{
            //    KillCounter++;
            //}


            if (data.LastTwoNumsSum % 10 == FilterHelper.LastLottery.LastTwoNumsSum % 10)
            {
                KillCounter++;
            }

            //int s = Math.Abs(data.LastTwoNumsSum - FilterHelper.LastLottery.LastTwoNumsSum);
            //if (s <= 2)
            //{
            //    KillCounter++;
            //}

        }

        /// <summary>
        /// Log
        /// </summary>
        /// <param name="issue"></param>
        /// <param name="fourDNumber"></param>
        /// <param name="type"></param>
        /// <param name="counter"></param>
        private static void MonitorLog(string issue, string fourDNumber, string type, int counter)
        {
            //Console.WriteLine("上期期号：" + issue + ":" + "被杀号码：" + fourDNumber + "-----" + type + "-----" + counter + "----------" + DateTime.Now);
        }

        /// <summary>
        /// 递归
        /// </summary>
        /// <param name="str"></param>
        /// <param name="m"></param>
        /// <param name="n"></param>
        private static void Pai(ref char[] str, int m, int n, ref List<string> list)
        {
            if (m < n)
            {
                for (int i = 0; i <= m; i++)
                {
                    Pai(ref str, m + 1, n, ref list);
                    Change(ref str, m);
                }
            }
            else
            {
                if (str.Length == 4)
                {
                    string data = str[0].ToString() + str[1] + str[2] + str[3];
                    list.Add(data);
                }
                if (str.Length == 3)
                {
                    string data = str[0].ToString() + str[1] + str[2];
                    list.Add(data);
                }
            }
        }

        /// <summary>
        /// 移位
        /// </summary>
        /// <param name="str"></param>
        /// <param name="m"></param>
        private static void Change(ref char[] str, int m)
        {
            char temp = str[0];
            for (int i = 0; i < m; i++)
            {
                str[i] = str[i + 1];
            }
            str[m] = temp;
        }
    }
}
